package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Insurance;
import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyCatalogQuery;
import cn.wolfcode.trip.base.service.IInsuranceService;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.management.Query;

@Controller
@RequestMapping("insurance")
public class InsuranceController {
    @Autowired
    private IInsuranceService insuranceService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model) {
        // 按照销售额降序排列
        qo.setOrderBy("account DESC");
        PageInfo pageInfo = insuranceService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "insurance/list";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Insurance entity) {
        insuranceService.saveOrUpdate(entity);
        return new JSONResult();
    }

    @RequestMapping("delete")
    @ResponseBody
    public Object deleteById(Long id) {
        insuranceService.deleteById(id);
        return new JSONResult();
    }

    @RequestMapping("listInsuranceCatalog")
    @ResponseBody
    public Object listInsuranceCatalogs() {
        return insuranceService.listAll();
    }
}
